package com.birth.memo.ui;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.birth.memo.R;

public class ViewCharacter extends Activity {
	
	private static final int LOAD_DIALOG = 2;
	
	private static final int CONTENT_LOAD_FINISH = 10;
	
	private WebView webView;
	
	private Handler handler = new Handler() {
		public void handleMessage(Message message) {
			switch (message.what) {
			case CONTENT_LOAD_FINISH:				
				dismissDialog(LOAD_DIALOG);				
				break;
			}
			super.handleMessage(message);
		}
	};
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);		
		this.setContentView(R.layout.view_character);
		
		showDialog(LOAD_DIALOG);  
		webView = (WebView)this.findViewById(R.id.wv);		
		webView.loadUrl("file:///android_asset/main.htm"); 
		webView.setWebViewClient(new WebViewClient(){  
            public boolean shouldOverrideUrlLoading(WebView view, String url) {              	
                return super.shouldOverrideUrlLoading(view, url);                  
            }  
            
            @Override
			public void onPageFinished(WebView view, String url) {            	
            	dismissDialog(LOAD_DIALOG);	 
				super.onPageFinished(view, url);
			}
            
			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				showDialog(LOAD_DIALOG);    
				super.onPageStarted(view, url, favicon);
			}
        });  
	}
	
	@Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {           
            case LOAD_DIALOG: {
                ProgressDialog dialog = new ProgressDialog(this);
                dialog.setMessage("加载中...");
                dialog.setIndeterminate(true);
                dialog.setCancelable(true);
                return dialog;
            }
        }
        return null;
    }

}
